﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour {
    Rigidbody2D rigi = null;
    void Start() {
        rigi = GetComponent<Rigidbody2D>();

    }

    [SerializeField]
    KeyCode W = KeyCode.W;
    [SerializeField]
    KeyCode A = KeyCode.A;
    [SerializeField]
    KeyCode D = KeyCode.D;
    [SerializeField]
    //bool right = false;
    float _velocity = 0f;

    float m_velocity = 0f;
    // Update is called once per frame
    void Update() {
        if (Input.GetKey(W)) {
            Jump();
        }
        if (Input.GetKey(A)) {
            if (_velocity - Time.deltaTime > -1)
                _velocity -= Time.deltaTime;
            else _velocity = -1.0f;
            Move();
        }
        if (Input.GetKey(D)) {
            if (_velocity + Time.deltaTime < 1)
                _velocity += Time.deltaTime;
            else _velocity = 1.0f;
            Move();
        }
    }
    private void Move() {
        rigi.velocity = new Vector2(_velocity * m_velocity, rigi.velocity.y);
    }
    void Jump() {
        rigi.velocity = new Vector2(rigi.velocity.x, 5.0f);
    }
}
